// pages/feedback/feedback.js
//获取app实例
const app = getApp();

Page({
  //页面的初始数据 
  data: {
    content: null
  },

  onLoad: function () {
    wx.request({
      url: app.baseURL + 'Mine&a=set_pay&user_id=' + app.globalData.userId + '&type=2',
      success: (res) => {
        console.log(res)
        if (res.data.status == 1) {
          this.setData({
            mobile: res.data.info.mobile,  //手机号0未绑定
          })
        }
      }
    })
  },

  //提交数据
  formSubmit: function (e) {
    const content = e.detail.value.content; //提交的内容
    const userId = app.globalData.userId; //用户id
    if (userId) {
      if (this.data.mobile == 0) {
        wx.showToast({
          title: '请先绑定手机号',
          icon: 'none',
          success: (res) => {
            setTimeout(function () {
              wx.redirectTo({
                url: '/pages/bindingMobile/bindingMobile',
              })
            }, 600)
          }
        })
        return;
      }
      if (!content) { wx.showToast({ title: '内容不能为空', icon: 'none' });return};
      wx.request({
        url: app.baseURL + 'Mine&a=option&user_id=' + userId + '&option=' + content,
        success: (res) => {
          if (res.statusCode == 200) {
            wx.showToast({ title: '反馈成功', mask: true }); 
            this.setData({ content: '' });
            setTimeout(() => {
              wx.navigateBack();
            }, 500);
          };
        }
      })
    }
  }
})